Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8346195: Fix static initialization problem in GDIHashtable #22736

Closed
wants to merge 1 commit into from

Conversation

magicus
Copy link
Member

@magicus magicus commented Dec 13, 2024

There has been a latent problem in GDIHashtable since time immemorial, but due to sheer luck it has not caused any issues for us. However, I managed to provoke it when I was doing some build changes.

This is the problem:
In GDIHashtable, there is a static field GDIHashtable::BatchDestructionManager manager, which is initialized in GDIHashtable.cpp.

In AwtPen, there is a static field GDIHashtable cache, which is initialized in awt_Pen.cpp.

The GDIHashtable constructor calls manager.add(this).

For this to work, the manager must have been initialized prior to the AwtPen. However, the order of which static initializers are run between different compilation units are not well-defined, and we've just been lucky so far that it works.

This problem is known as the "Static Initialization Order Fiasco", see e.g. https://en.cppreference.com/w/cpp/language/siof

I have solved this by encapsulating the static manager instance in a method, which guarantees that it has been initialized before use. This seemed to me to be the cleanest solution.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8346195: Fix static initialization problem in GDIHashtable (Bug - P2)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22736/head:pull/22736
$ git checkout pull/22736

Update a local copy of the PR:
$ git checkout pull/22736
$ git pull https://git.openjdk.org/jdk.git pull/22736/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 22736

View PR using the GUI difftool:
$ git pr show -t 22736

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22736.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 13, 2024

👋 Welcome back ihse! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Dec 13, 2024

@magicus This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8346195: Fix static initialization problem in GDIHashtable

Reviewed-by: jwaters, prr

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 64 new commits pushed to the master branch:

  • a5503fb: 8346432: java.lang.foreign.Linker comment typo
  • fbd76ca: 8337016: serviceability/jvmti/RedefineClasses/RedefineLeakThrowable.java gets Metaspace OOM
  • baeb3d9: 8346304: SA doesn't need a copy of getModifierFlags
  • 99af595: 8345942: Separate source output from class output when building microbenchmarks
  • 8a64595: 8346282: [JVMCI] Add failure reason support to UnresolvedJava/Type/Method/Field
  • 725079b: 8345506: jar --validate may lead to java.nio.file.FileAlreadyExistsException
  • 5e25c48: 8346289: Confusing phrasing in IR Framework README / User-defined Regexes
  • fbbc7c3: 8346120: VirtualThreadPinned event recorded for Object.wait may have wrong duration or may record second event
  • 466c00a: 8346234: javax/swing/text/DefaultEditorKit/4278839/bug4278839.java still fails in CI
  • bd3c0be: 8268611: jar --validate should check targeted classes in MR-JAR files
  • ... and 54 more: https://git.openjdk.org/jdk/compare/68aa4d44ff95493d66a740be99e6cf533bec5bc8...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 13, 2024
@openjdk
Copy link

openjdk bot commented Dec 13, 2024

@magicus The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Dec 13, 2024
@mlbridge
Copy link

mlbridge bot commented Dec 13, 2024

Webrevs

@magicus
Copy link
Member Author

magicus commented Dec 17, 2024

Any reviewers on this?

Copy link
Contributor

@TheShermanTanker TheShermanTanker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reviewers on this?

Looks ok and trivial to me (But I'm not a Reviewer, unfortunately)

Copy link
Contributor

@prrace prrace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this is already on my list of reasons I don't like C++.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 17, 2024
@magicus
Copy link
Member Author

magicus commented Dec 17, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Dec 17, 2024

Going to push as commit 03821d9.
Since your change was applied there have been 64 commits pushed to the master branch:

  • a5503fb: 8346432: java.lang.foreign.Linker comment typo
  • fbd76ca: 8337016: serviceability/jvmti/RedefineClasses/RedefineLeakThrowable.java gets Metaspace OOM
  • baeb3d9: 8346304: SA doesn't need a copy of getModifierFlags
  • 99af595: 8345942: Separate source output from class output when building microbenchmarks
  • 8a64595: 8346282: [JVMCI] Add failure reason support to UnresolvedJava/Type/Method/Field
  • 725079b: 8345506: jar --validate may lead to java.nio.file.FileAlreadyExistsException
  • 5e25c48: 8346289: Confusing phrasing in IR Framework README / User-defined Regexes
  • fbbc7c3: 8346120: VirtualThreadPinned event recorded for Object.wait may have wrong duration or may record second event
  • 466c00a: 8346234: javax/swing/text/DefaultEditorKit/4278839/bug4278839.java still fails in CI
  • bd3c0be: 8268611: jar --validate should check targeted classes in MR-JAR files
  • ... and 54 more: https://git.openjdk.org/jdk/compare/68aa4d44ff95493d66a740be99e6cf533bec5bc8...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 17, 2024
@openjdk openjdk bot closed this Dec 17, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Dec 17, 2024
@openjdk
Copy link

openjdk bot commented Dec 17, 2024

@magicus Pushed as commit 03821d9.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@magicus magicus deleted the fix-siof-in-gdihashtable branch December 17, 2024 17:59
@magicus
Copy link
Member Author

magicus commented Dec 17, 2024

I am not sure if this is already on my list of reasons I don't like C++.

I did not know about this until I tried to resolve this bug (it took some time to figure out the problem). I can surely put it on my such list. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants